#!/usr/bin/python3
# -*- coding: utf8 -*-
# Date   : 2021/09/01
# Author : Kwan
# Email  : allenxian@live.com
# Blog   : https://my.oschina.net/u/4173440

import wmi
from os import getlogin
from math import ceil, pow
from getmac import get_mac_address


class Client:
    def __init__(self) -> None:
        self.CPU = ""
        self.Memory = ""
        self.Disk = ""
        self.GPU = ""
        self.Board = ""
        self.SerialNumber = ""
        self.Windows = ""
        self.Arch = ""
        self.HostName = ""
        self.Domain = ""
        self.LoginUser = ""
        self.Mac = ""

    def device_scan(self):
        # 设备扫描
        c = wmi.WMI()
        # 获取CPU型号,允许多路
        self.CPU = ",".join([i.Name for i in c.Win32_Processor()])
        # 获取Windows版本
        winos = c.Win32_OperatingSystem()[0]
        self.Windows = winos.Caption
        if "32" in winos.OSArchitecture:
            self.Arch = "32位"
        else:
            self.Arch = "64位"
        self.HostName = winos.CSName
        winsys = c.Win32_ComputerSystem()[0]
        # 内存信息
        self.Memory = f"{ceil(int(winsys.TotalPhysicalMemory) / pow(1024, 3))}GB"
        self.Domain = winsys.Domain
        # 获取硬盘信息
        self.Disk = ",".join([disk.Model for disk in c.Win32_DiskDrive()])
        # 获取主板信息
        board = c.Win32_BaseBoard()[0]
        self.Board = f"{board.Manufacturer} {board.Product}"
        self.SerialNumber = board.SerialNumber
        # 显卡信息
        self.GPU = ",".join([gpu.Name for gpu in c.Win32_VideoController()])
        # 当前登录用户
        self.LoginUser = getlogin()
        self.Mac = get_mac_address().upper()
